Skip to content

Remove paramiko hacks - #464

Open
uruun wants to merge 2 commits into
MarketSquare:masterfrom
uruun:remove_paramiko_hacks
Open

Remove paramiko hacks#464
uruun wants to merge 2 commits into
MarketSquare:masterfrom
uruun:remove_paramiko_hacks

Conversation

@uruun

@uruun uruun commented Sep 2, 2024

Copy link
Copy Markdown

Remove two paramiko hacks done in client.py. They both seem like very old workarounds and their functionality can be achieved through official paramiko APIs.

The first one set the banner timeout for paramiko Transport to 45 seconds. banner_timeout can be set in paramiko SSHClient.connect or with Transport.banner_timeout, I went with connect as it seems to be the expected way to do it. This might be a breaking change if someone is using the SSHLibrary SSHClient.client directly as then the timeout will be the default 15 seconds.

The second one is a workaround for % symbols in file paths reported in 2012: http://code.google.com/p/robotframework-sshlibrary/issues/detail?id=55 . It seems this has been fixed in paramiko in 2014 here: paramiko/paramiko@6e9abc3 . As it has been fixed for so long I hope everyone moved on to newer paramiko and this is not needed anymore.

Also removed small remaining Python 2 compatibility.

@uruun

uruun commented Sep 3, 2024

Copy link
Copy Markdown
Author

The Read Until With Encoding Errors On Strict test is failing because of #431, issue #465 .

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes legacy Paramiko monkeypatches from client.py (banner timeout override and SFTP %-escaping workaround) in favor of using Paramiko’s official APIs, and drops a remaining Python 2 compatibility import.

Changes:

  • Removed Paramiko Transport/SFTPClient monkeypatch “hacks” and replaced banner handling with SSHClient.connect(..., banner_timeout=...).
  • Introduced a module-level BANNER_TIMEOUT = 45 used across connection paths.
  • Removed from __future__ import print_function from library.py.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/SSHLibrary/library.py Removes the Python 2-era print_function future import.
src/SSHLibrary/client.py Removes Paramiko monkeypatches and applies banner_timeout through SSHClient.connect.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/SSHLibrary/client.py
Comment on lines 878 to +882
self.client.connect(self.config.host, self.config.port, username,
password, look_for_keys=look_for_keys,
allow_agent=allow_agent,
timeout=float(self.config.timeout), sock=sock_tunnel)
timeout=float(self.config.timeout), sock=sock_tunnel,
banner_timeout=BANNER_TIMEOUT)
Comment thread src/SSHLibrary/client.py
Comment on lines 890 to +894
self.client.connect(self.config.host, self.config.port, username,
password, look_for_keys=look_for_keys,
allow_agent=allow_agent,
timeout=float(self.config.timeout), sock=sock_tunnel)
timeout=float(self.config.timeout), sock=sock_tunnel,
banner_timeout=BANNER_TIMEOUT)
Comment thread src/SSHLibrary/client.py
Comment on lines 936 to +941
self.client.connect(self.config.host, self.config.port, username,
password, key_filename=key_file,
allow_agent=allow_agent,
look_for_keys=look_for_keys,
timeout=float(self.config.timeout),
sock=sock_tunnel)
sock=sock_tunnel, banner_timeout=BANNER_TIMEOUT)
Comment thread src/SSHLibrary/client.py
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(str(host), int(port), username="bad-username")
client.connect(str(host), int(port), username="bad-username", banner_timeout=BANNER_TIMEOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants